home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
tell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
3KB
|
145 lines
#ifndef __lint
static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/tell.c,v 1.1 1994/06/01 22:21:32 dg1rtf Exp $";
#endif
#define _HPUX_SOURCE
#include <stdio.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#include "bbs.h"
#include "bbs.hd"
static int err_flag;
static FILE *fpbbs;
static FILE *fpsendmail;
static FILE *fbbs;
const struct cmdtable cmdtable[1];
/* In rerase.c: */
int main(int argc, char **argv);
static char *get_cmd_from_path(char *path);
/*---------------------------------------------------------------------------*/
static char *get_cmd_from_path(char *path)
{
char *cp;
static char tmp[1024];
strcpy(tmp, path);
cp = strrchr(tmp, '@');
if (!cp) return "EXIT";
*cp = 0;
cp = strrchr(tmp, '@');
return cp ? (cp + 1) : tmp;
}
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
struct index index;
struct passwd *pw;
char buffer[4096];
char buf[4096];
char command[1024];
int status;
if (getuid()) {
pw = getpwnam(bbsadm);
if(getuid() != pw->pw_uid) {
perror("permission denied");
return 1;
}
}
if (chdir(WRKDIR)) {
mkdir(WRKDIR, 0755);
if(chdir(WRKDIR)) halt();
}
read_config();
pw = getpwnam(telluser);
if (!(pw)) {
perror("cann't find such user");
return 1;
}
if ((fdindex = open(INDEXFILE, O_RDWR, 0644)) < 0) return 1;
unlink("/tmp/bbs_tell");
for (; ; ) {
if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop;
if (!(index.flags & DELETED)) {
if (!strcmp(index.to,"T") && !strcmp(index.at,Myhostname)) {
if (fork() == 0) {
setuid(pw->pw_uid);
fpbbs=popen("exec bbs > /tmp/bbs_tell","w");
if(!fpbbs) {
puts("cannot open bbs");
close(fdindex);
return 1;
}
fprintf(fpbbs,"%s\n",get_cmd_from_path(index.subject));
fprintf(fpbbs,"QUIT\n");
pclose(fpbbs);
exit (0);
} else
wait(&status);
fpbbs=popen("exec bbs > /dev/null","w");
if(!fpbbs) {
puts("cannot open bbs");
close(fdindex);
return 1;
}
fbbs=fopen("/tmp/bbs_tell","r");
fprintf(fpbbs,"SEND %s@%s < %s\n",index.from,get_host_from_path(index.subject),
Myhostname);
fprintf(fpbbs,"TELL-Response de %s\n",Myhostname);
fprintf(fpbbs,"%s response command: %s\n\n",Myhostname,
get_cmd_from_path(index.subject));
while (!feof(fbbs)) {
fgets(buffer,sizeof(buffer),fbbs);
if (!strncmp(prompt,buffer,strlen(prompt))) {
strcpy(buf,&buffer[strlen(prompt)]);
strcpy(buffer,buf);
}
fprintf(fpbbs,"%s",buffer);
}
fprintf(fpbbs,"\nthank you, for your interest\n");
fprintf(fpbbs,"\n73 de %s\n",Myhostname);
fprintf(fpbbs,"***end\nDESTROY %d\nBYE\n",index.mesg);
pclose(fpbbs);
fclose(fbbs);
unlink("/tmp/bbs_tell");
}
}
}
stop:
close(fdindex);
return 0;
}